<?php
	/**
	 * CargoAgentAction 货物代理模块
	 * @access public
	 */
class CargoAgentAction extends Action
{
	var $model = "CargoAgent";
	var $view_template = "";
	
	public function index(){
		$this->display("CargoAgent/agency");
	}
	/**
	 * show
	 * @access public 
	 *GET的方法获取，$judge = 1,按运货量排名查询，judge = 0，按服务质量排名
	                 $q 为搜索内容
	 * @return void
	 */
	public function show(){
		$judge = $_GET['judge'];
		$q = '';
		if(!empty($_GET['q'])){
			$q = " and description like '%{$_GET['q']}%'";
		}
		$instance = new Model ($this->model);
		import("ORG.Util.Page");
		$count = $instance->where('state = 1'.$q)->count();
		$Page = new Page($count,2);
		$show = $Page->show();
		if($judge == 1){
			$list = $instance->where('state = 1'.$q)->limit($Page->firstRow.','.$Page->listRows)->order("rank")->select();
		}else{
			$list = $instance->where('state = 1'.$q)->limit($Page->firstRow.','.$Page->listRows)->order("quality")->select();
		}
		$this->assign("list",$list);
		$this->assign("show",$show);
		$this->display("CargoAgent/sort_list");
	}
	/**
	 * view
	 * @access public 
	 * @return void
	 */
	public function view(){
		if(!empty($_GET['id'])){
			$instance = new Model ($this->model);
			$list = $instance->GetById($_GET['id']);
			if($list){
				$this->assign("list",$list);
				$this->display("CargoAgent/description");
			}else{
				$this->error("查看项不存在");
			}
		}else{
			$this->error("非法操作");
		}
	}

	public function view_random(){
		$instance = new Model ($this->model);
		$list = $instance->find();
		if($list){
			$this->assign("list",$list);
			$this->display("CargoAgent/description");
		}else{
			$this->error("查看项不存在");
		}
		
	}
}
?>
